import { httpApi } from '@/utils/config';
export function request(config: any) {
	// 解构赋值
	let {
		data = {},
		method = 'POST'
	} = {
		...config
	};
	return new Promise((resolve, reject) => {
		let contentType = '';
		switch (method) {
			case 'POST':
				contentType = 'application/json';
				break;
			case 'GET':
				contentType = 'application/x-www-form-urlencoded';
				break;
			default:
				break;
		}
		uni.request({
			url: httpApi + config.url,
			header: {
				'Content-Type': contentType
			},
			method: method,
			data: {
				...data
			},
			success: (res: any) => {
				if(res.data.result==1){
					resolve(res.data)
				} else {
					uni.showToast({
						title:res.data.msg,
						icon:'none'
					})
				}
			},
			fail: (err) => {
				reject(err);
			},
			complete: () => {}
		});
	});
}
